/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.typhosoft.photohz2o.server;

import com.typhosoft.jcommon.bean.CPhoto;
import com.typhosoft.jcommon.network.CDefaultPhotoConsumer;
import com.typhosoft.jcommon.photo.IPathProvider;

import java.io.IOException;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * @author SantonocitoM
 */
class CPhotoConsumer extends CDefaultPhotoConsumer {

    private final static ArrayBlockingQueue<CPhoto> fPhotoToSend = new ArrayBlockingQueue(10);

    public CPhotoConsumer(IPathProvider pathProvider) {
        super(pathProvider);
    }

    @Override
    public void writePhoto(CPhoto photo, String path) throws IOException {
        super.writePhoto(photo, path);
        fPhotoToSend.offer(photo);
        Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Write Image: " + path);
    }

    public CPhoto getNextPhoto() throws InterruptedException {
        CPhoto photo;
        photo = fPhotoToSend.take();
        return photo;
    }
}
